<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="tabtop">
          <div v-for="(item, index) in contractTypelist" :key="index" @click="choose(item.id)">
            <div :class="currenindex == item.id ? 'active' : 'text'">
              {{ item.value }}
            </div>
            <div v-if="
                currenindex !== item.id &&
                currenindex !== index + 2 &&
                index !== 4
              " class="hr"></div>
          </div>
        </div>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <transition name="from"></transition>
            <span v-show="!showCardNav">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </span>
            <transition name="to"></transition>
            <span v-show="showCardNav">
              <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
            </span>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px">主合同单位</span>
                <el-input v-model="tableParam.supplierName" style="width: 240px" clearable @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px">
                <span style="margin-right: 12px">站点名称</span>
                <el-input v-model="tableParam.stations" style="width: 240px" clearable @keyup.enter.native="gettableData()" />
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="searchDialog = true">高级搜索</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <contract v-if="currenindex == 1" ref="contract" @sumbit="init"></contract>
          <car v-if="currenindex == 2" ref="car" @sumbit="init"></car>
          <equipment v-if="currenindex == 3" ref="equipment" @sumbit="init"></equipment>
          <pumpTube v-if="currenindex == 4" ref="pumpTube" @sumbit="init"></pumpTube>
          <outsourcing v-if="currenindex == 5" ref="outsourcing" @sumbit="init"></outsourcing>
        </div>
      </el-main>
    </el-container>
    <el-dialog v-dialogDrag :visible.sync="searchDialog" width="580px" :close-on-click-modal="false" :before-close="search">
      <span slot="title" class="dialog-title">高级搜索</span>
      <div class="dialoginfo">
        <el-form ref="reftableParam" :inline="true" :model="tableParam" label-width="110px">
          <el-form-item>
            <span slot="label">供应商类别</span>
            <el-input v-model="tableParam.supplierType" tplaceholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">合作等级</span>
            <el-select v-model="tableParam.cooperationClassId" placeholder="请选择">
              <el-option v-for="item in cooperationIdlist" :key="item.id" :label="item.itemName" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <span slot="label">招标编号</span>
            <el-input v-model="tableParam.callForBidsNumber" tplaceholder="请输入" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="searchDialog=false,tableParam.supplierType='',tableParam.cooperationClassId='',tableParam.callForBidsNumber=''">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="gettableData(),searchDialog=false">搜 索</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import breaDcrumb from "@/components/breadcrumb";
import contract from "./components/contract.vue"; //原物料
import car from "./components/car.vue"; //车辆外包
import equipment from "./components/equipment.vue"; //设备外包
import pumpTube from "./components/pumpTube.vue"; //泵管外包
import outsourcing from "./components/outsourcing.vue"; //外协
import { getDicsType } from "@/api/common.js";
export default {
  mixins: [mixin],
  components: {
    contract,
    car,
    equipment,
    outsourcing,
    pumpTube,
    breaDcrumb,
  },
  data() {
    return {
      currenindex: 1,
      contractTypelist: [
        { value: "原物料", id: 1 },
        { value: "车辆外包", id: 2 },
        { value: "设备外包", id: 3 },
        { value: "泵管外包", id: 4 },
        { value: "往来协作", id: 5 },
      ],
      searchDialog: false,
      supplierTypelist: [],
      cooperationIdlist: [],
      pagesType: 0,
      tableParam: {
        page: 1,
        pageSize: 10,
      },
      showCardNav: true,
    };
  },
  created() {
    this.tableParam = { ...this.tableParam, supplierName: "", stations: "", supplierType: '', cooperationClassId: '', callForBidsNumber: '' };
    getDicsType({ codes: "supplierType,Levelofcooperation" }).then((res) => {
      this.supplierTypelist = res.data.supplierType.items;
      this.cooperationIdlist = res.data.Levelofcooperation.items;
    });
  },
  mounted() {
    this.gettableData();
  },
  methods: {
    init() {
      setTimeout(() => {
        this.tableParam = this.$options.data().tableParam;
        if (this.currenindex == 1) {
          this.tableParam.contractTypeId = 1;
          this.$refs.contract.initt(this.tableParam);
        } else if (this.currenindex == 2) {
          this.tableParam.contractTypeId = 2;
          this.$refs.car.initt(this.tableParam);
        } else if (this.currenindex == 3) {
          this.tableParam.contractTypeId = 3;
          this.$refs.equipment.initt(this.tableParam);
        } else if (this.currenindex == 4) {
          this.tableParam.contractTypeId = 4;
          this.$refs.pumpTube.initt(this.tableParam);
        } else if (this.currenindex == 5) {
          this.tableParam.contractTypeId = 5;
          this.$refs.outsourcing.initt(this.tableParam);
        }
      }, 100);
    },
    gettableData() {
      setTimeout(() => {
        this.tableParam.page = 1;
        if (this.currenindex == 1) {
          this.tableParam.contractTypeId = "1";
          this.$refs.contract.srarch(this.tableParam);
        } else if (this.currenindex == 2) {
          this.tableParam.contractTypeId = "2";
          this.$refs.car.srarch(this.tableParam);
        } else if (this.currenindex == 3) {
          this.tableParam.contractTypeId = "3";
          this.$refs.equipment.srarch(this.tableParam);
        } else if (this.currenindex == 4) {
          this.tableParam.contractTypeId = "4";
          this.$refs.pumpTube.srarch(this.tableParam);
        } else if (this.currenindex == 5) {
          this.tableParam.contractTypeId = "5";
          this.$refs.outsourcing.srarch(this.tableParam);
        }
      }, 100);
    },
    choose(num) {
      this.currenindex = num;
      this.gettableData();
    },
    search() {
      this.searchDialog = false;
      this.gettableData();
    },
  },
};
</script>

<style lang="scss" scoped>
.el-input,
.el-select {
  width: 320px;
}
.dialoginfo {
  padding: 0 20px 0 20px;
}
.dialoginfo-title {
  display: flex;
  align-items: center;
  height: 50px;
  > div {
    width: 4px;
    height: 20px;
    background: $bg_color;
  }
  > span {
    padding-left: 10px;
    font-size: 20px;
    color: $bg_color;
    font-weight: bold;
  }
}
.tabtop {
  width: 948px;
  display: flex;
  border: $bg_color 1px solid;
  border-radius: 4px;
  margin: 20px 20px 0 20px;
  > div {
    height: 40px;
    width: 190px;
    font-size: 16px;
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    .text {
      width: 188px;
      @include discen;
      line-height: 40px;
      color: $bg_color;
    }
    .active {
      width: 188px;
      @include discen;
      line-height: 40px;
      color: #ffffff;
      background: $bg_color;
      border-radius: 4px;
    }
    .hr {
      height: 20px;
      width: 2px;
      background: $bg_color;
    }
  }
}
</style>
